home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93b.txt
/
000040_icon-group-sender _Wed Apr 28 12:56:19 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-06-16
|
3KB
Received: by cheltenham.cs.arizona.edu; Wed, 28 Apr 1993 13:06:06 MST
Message-Id: <9304281953.AA17496@enlil.premenos.sf.ca.us>
From: Ken Walker <kwalker@shara.premenos.sf.ca.us>
Subject: var paramters
To: icon-group@cs.arizona.edu
Date: Wed, 28 Apr 93 12:56:19 PDT
Mailer: Elm [revision: 66.25]
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
> from Richard L. Goerwitz:
>
> So-called "var" parameters in Pascal are a way of introducing side-
> effects. These are not permitted in Icon per se. One usually does
> not want or need them, although I have often wondered whether adding
> them would be difficult - if they were done precisely as in Pascal
> (i.e. not as in C, which might break Icon's type-safe scheme).
>From an implementation perspective, I'd prefer the in/out style of
parameter passing, where the updated value of an out parameter is only
copied back to the caller's variable upon return and suspend (should
they be updated on failure?). There is also an advanatage from the
language philosophy point of view: in the case of an out parameter,
you can consider the call rather than the called procedure as being
what updates a local variable passed as an argument; this means that
local variables are still only updated by the procedure they belong
to, protecting their "local" status.
Those not interested in "technical" matters might want to skip the
rest of the discussion.
I haven't investigated this in detail, but I think the following is
what is needed to add in/out parameters to Icon. In the translator,
the grammar for paramters must be updated and flags must be added
to the symbol table to distinguish in, out, and in-out parameters.
In the runtime system, in/out information must be added to procedure
blocks. Invocation must keep a copy of variable refereces for out
parameters and, on return, must assign the updated parameter values to
those variables before popping the parameters from the stack. Suspend
must also copy the updated out parameter values to the variables. The
linker must be updated to produce the procedure blocks with the in-out
information.
As one might expect, the compiler is a little harder because of
optimizations. However, in-out parameters are easier than var
parameters; type inference can be modified to handle var paramters,
but it would make type inference more expensive. The modifications
to the compiler's grammar and symbol table are similar to those of
the translator for the interpreter. The abstract invocation of type
inference must be updated to mirror the semantics of actual invocation;
if you understand type inference, this is probably not harder than
updating invocation in the run-time system. Non-optimized invocation
can be handled similar to the way invocation is handled in the interpreter,
though some of the inplementation conventions are different. One way to
handle optimized procedure invocation is to not optimize if there are
out parameters (but that's not much fun :-). The current case analysis
for optimizing invocation is rather gross and optimizing out parameter
passed will make it worse, but clearly it can be done.
Can anyone think of something I've missed?
Note: the preceding discussion should not be taken to mean that
I'm considering trying to implement in/out parameters in the
immediate future.
Ken Walker, kwalker@premenos.sf.ca.us